﻿@model MyMvc.Model.Models.Article
@{
    Layout = null;
}
<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <title>文章管理中心</title>
    <link href="~/Content/jquery-easyui-1.3.1/themes/icon.css" rel="stylesheet" />
    <link href="~/Content/jquery-easyui-1.3.1/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/Site.css" rel="stylesheet" />
    @*<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>*@

    <script src="~/Content/jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
    <script src="~/Content/jquery-easyui-1.3.1/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.3.1/locale/easyui-lang-zh_CN.js"></script>

    @*修改时间格式的Js文件*@
    <script src="~/Content/jquery-easyui-1.3.1/datapattern2.js"></script>

    <script src="~/Scripts/ckeditor/ckeditor.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#ddlCategory").combobox({
                onChange: function () {
                    GetType()
                }
            });
            //$("#ddlCategory").combobox();
            AddArticleButtonClickEvent();
        });
        //得到某个一级分类的二级分类
        function GetType() {
            $("#ddlType").combobox("clear"); //清空二级菜单SELECT控件
            var url = "/AddArticle/GetTypeList/" + $("#ddlCategory").combobox("getValue");
            //alert("读取二级分类");
            $.getJSON(url, function (data) {
                var json = [];
                $.each(data, function (i, item) {
                    json.push({ "text": item.TypeName, "id": item.ID });
                });
                $("#ddlType").combobox("loadData", json);
                $("#ddlType").combobox("select", json[0].id);
            });
        }


        $.fn.datebox.defaults.formatter = function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
        };
        $.fn.datebox.defaults.parser = function (s) {
            if (!s) return new Date();
            var ss = s.split('-');
            var y = parseInt(ss[0], 10);
            var m = parseInt(ss[1], 10);
            var d = parseInt(ss[2], 10);
            if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
                return new Date(y, m - 1, d);
            } else {
                return new Date();
            }
        };
        //实现添加的操作
        function AddArticleButtonClickEvent() {
            $("#btnAdd").click(function () {
                //验证表单是否通过
                var validate = $('#ff').form('validate');
                //构造传递的参数，
                var da = CKEDITOR.instances.Content1.getData();
                if (validate == false) {
                    return false;
                }
                else {
                    //构造传递的参数，
                    var postData = {
                        Title: $("#Title").val(),
                        //Category: $("#ddlCategory").combobox('getValue'),
                        Category: $("#ddlCategory").combobox('getValue'),
                        SubCategory: $("#ddlType").combobox('getValue'),//.val(),
                        //Category: $("#ddlCategory").val(),
                        Content1: escape(da),
                        Count: $("#Title").val(),
                        Author: $("#Author").val(),
                    };
                }
                //异步传递数据到前台进行添加
                $.post("/AddArticle/AddArticle", postData, function (data) {
                    if (data == "OK") {
                        alert("dsa");
                        ClearTextBox();
                        $.messager.alert("友情提示", "添加成功");
                    }
                    else {
                        $.messager.alert("友情提示", "添加失败，请您检查");
                    }
                });

            });
        }
        //当添加或者修改完成后清空文本框中的值
        function ClearTextBox() {
            //UName,Pwd,PwdOK
            $("#Title").val("");
            $("#Author").val("");
        }
        //返回文章列表
        function backArticle() {
            location.href = "/Literature/Index";
        }
    </script>
</head>

<body>
    <div>
        <form id="ff" method="post" novalidate="novalidate">
            <fieldset>
                <legend>添加一篇新的文章</legend>
                <p>
                    <label for="Title">标题：</label>
                    <input class="easyui-validatebox" type="text" id="Title" name="Title" data-options="required:true,validType:'length[1,32]'" />
                    <label for="Category">所属类别：</label>
                    <select id="ddlCategory" name="ddlCategory" class="easyui-combobox" style="width: 200px">
                        <option value="0" selected="selected">-- -- --请选择-- -- --</option>
                        <option value="1">业务范围</option>
                        <option value="2">技术优势</option>
                        <option value="3">工程实例</option>
                        <option value="4">专业文献</option>
                    </select>
                    <select id="ddlType" name="ddlType" class="easyui-combobox" style="width: 200px" valueField="id" textField="text" >
                        <option value="please" selected="selected">-- -- --请选择-- -- --</option>
                    </select>

                    <label for="Author">作者：</label>
                    <input class="easyui-validatebox" type="text" id="Author" name="Author" data-options="required:true,validType:'length[1,32]'" />
                </p>
                <p>
                    <label for="Content1">内容:</label>
                    <textarea cols="150" rows="10" id="Content1" name="Content1"></textarea>
                    <script type="text/javascript">
                        CKEDITOR.replace('Content1', {
                            skin: 'kama',
                            height: 150,
                            width: 950
                        });
                    </script>
                </p>
                <p>
                    <a href="#" class="easyui-linkbutton" id="btnAdd" iconcls="icon-ok">添加</a>
                    <a href="#" class="easyui-linkbutton" onclick="backArticle()" id="btnBack" iconcls="icon-ok">返回文章管理页面</a>
                </p>
            </fieldset>
        </form>
    </div>
</body>
</html>
